import { defineStore, storeToRefs } from 'pinia'
import { msgTip } from '@/hooks/useMsgTip.js'

import useUIStore from '@/stores/UI.js'
import { useSimpleTaskData } from '@/stores/simpleTaskData.js'

const UIStore = useUIStore()
const { UIOnStart, UIOnComplete } = UIStore

const simpleTaskData = useSimpleTaskData()
const { indicator, currentIndex } = storeToRefs(simpleTaskData)
const { allTaskData, PFs } = simpleTaskData

export const useSimpleUIStore = defineStore('SimpleUIStore', () => {
  const selectDisabled = ref(false)
  const drawerVisible = ref(false)
  const UIOnSimpleSubmit = () => {
    UIOnStart()
    selectDisabled.value = true
  }

  const onSimpleTaskCompleteUI = () => {
    UIOnComplete()
    selectDisabled.value = false
  }

  const onSimpleTaskComplete = () => {
    if (indicator.value === 'obj') {
      allTaskData[currentIndex.value][indicator.value].series[1].data = PFs[currentIndex.value]
    }
    msgTip('Success', 'simple task completed', 'success')
    onSimpleTaskCompleteUI()
  }
  return {
    selectDisabled,
    UIOnSimpleSubmit,
    onSimpleTaskComplete,
    drawerVisible,
    onSimpleTaskCompleteUI
  }
})
